package com.edu.gateway.base;

import com.netflix.ribbon.proxy.annotation.Http;
import lombok.Data;
import org.springframework.http.HttpStatus;


public class R<T> {


    private String code = String.valueOf(HttpStatus.OK.value());
    private String msg = "success";
    private T data;

    public String getCode() {
        return code;
    }

    public R<T> setCode(String code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public R<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public T getData() {
        return data;
    }

    public R<T> setData(T data) {
        this.data = data;
        return this;
    }

    public boolean isSuccess() {
        return String.valueOf(HttpStatus.OK.value()).equals(code);
    }

    public static R<String> ok() {
        return ok("");
    }
    public static <T> R<T> ok(T data) {
        R<T> r=new R<T>();
        r.setData(data);
        return r;
    }

    public static R fail() {
        R result = new R();
        return result.setCode(String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value()));
    }

    public static R fail(String message) {
        return R.fail().setMsg(message);
    }

}
